//引入组件 14:20

import React,{FC} from 'react'
import {Switch,Route,Redirect} from 'react-router-dom'

import {Routes} from '../types/index'

const RouterView:FC<Routes> =({routes})=>{
    return(
        <Switch>
            {
                routes.map((item,index)=>{
                    if(item.to){
                        return <Redirect key={index} from={item.from} to={item.to}/>
                    }
                    return <Route
                    key={index}    
                    path={item.path}
                    render={routerConfig=><item.component
                        {...routerConfig}
                        routes={item.children||[]}
                    />}
                    />
                })
            }
        </Switch>
    )
}

export default RouterView
//14；24